﻿using System;
using GameEngine.Model;
using GameEngine.Model.Data;
using GameEngine.View;
using GameEngine.View.Components;
using PureMVC.Interfaces;
using PureMVC.Patterns;

namespace GameEngine.Controller
{
    public class DestroyGameCommand<MyIdType>:SimpleCommand
        where MyIdType : IComparable<MyIdType>
    {
        override public void Execute(INotification notification)
        {
            IGameVO<MyIdType> gameVO = notification.Body as IGameVO<MyIdType>;
            
            foreach (IThingTypeVO<MyIdType> thingType in gameVO.ThingTypes)
            {
                //ApplicationFacade.Instance.RegisterProxy(ModelFacade<MyIdType>.Instance.CreateThingTypeDataProxy(thingType));
                ApplicationFacade.Instance.RemoveProxy(IThingTypeDataProxyConstants<MyIdType>.CreateDataProxyName(thingType));
            }
            //ApplicationFacadeHelper<MyIdType>.SetLevel(gameVO.Levels[gameVO.CurrentLevel]);
            SendNotification(ApplicationFacade.DESTROYLEVEL_COMMAND, ModelFacade<MyIdType>.Instance.Engine.Game.Levels[gameVO.LevelOrder[gameVO.CurrentLevel]]);
            
            //ApplicationFacade.Instance.RegisterMediator(
            //    ViewFacade<MyGameView, MyLevelView, MyWorldView, MyMapView, MyThingView, MyIdType, MyBaseUIElementType>.Instance.CreateGameMediator(
            //        gameDataProxy,
            //        ViewFacade<MyGameView, MyLevelView, MyWorldView, MyMapView, MyThingView, MyIdType, MyBaseUIElementType>.Helper.GetLevelMediator(gameVO.CurrentLevel),
            //        ViewFacade<MyGameView, MyLevelView, MyWorldView, MyMapView, MyThingView, MyIdType, MyBaseUIElementType>.Instance.CreateGameView()));
            ApplicationFacade.Instance.RemoveMediator(GameMediatorHelper<MyIdType>.GetMediatorNameFromProxy(ModelFacade<MyIdType>.Instance.Engine.Game));

            ApplicationFacade.Instance.RemoveProxy(ModelFacade<MyIdType>.Instance.Engine.Game.ProxyName);
            ModelFacade<MyIdType>.Instance.Engine.Game = null;

        }
    }
}
